package com.sm.dao;

import com.sm.entity.UserWelfare;
import com.sm.entity.Welfare;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserWelfareDao {
    //查询福利
    @Select("select * from user_welfare where uid = #{uid} and month = #{month}")
    @Results(value = {
            @Result(id = true,property = "uid",column = "uid"),
            @Result(property = "username",column = "username"),
            @Result(property = "email",column = "email"),
            @Result(property = "phoneNum",column = "phonenum"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "date",column = "date"),
            @Result(property = "status",column = "status"),
            @Result(property = "welfares",column = "uid",javaType = java.util.List.class ,many = @Many(select = "com.sm.dao.WelfareDao.findWelfareByUid"))
    })
    public UserWelfare findWelfareByUid(@Param("uid")Integer uid,@Param("month")Integer month);

    //给员工添加福利
    @Insert("insert into user_welfare(uid,wid,month) values(#{uid},#{wid},#{month})")
    public void addUserWelfare(@Param("uid") Integer uid, @Param("wid")Integer wid,@Param("month")Integer month);

    //删除员工福利
    @Delete("delete from user_welfare where month = #{month}")
    public void deleteUserWelfare(Integer month);

}